/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//package comits.web.client.servlets.demo;
package comits.web.client.servlets.demo;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.StringTokenizer;
import java.util.logging.LogManager;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


import comits.business.tiers.dao.EmployeDAO;
import comits.business.tiers.dao.EmployeDAOImpl;
import comits.business.tiers.main.DRPMain;
import comits.business.tiers.requests.manager.ws.RequestsManager;
import comits.business.tiers.rp.tasks.ws.ControleurCalculAppro;
import comits.business.tiers.utilitaires.LoggingOutputStream;
/*import comits.web.client.servlets.gestion.drp.ComITSBusinessTiers10SNAPSHOTStub;
import comits.web.client.servlets.gestion.drp.ComITSBusinessTiers10SNAPSHOTStub.LancerCalculDRP;
import comits.web.client.servlets.gestion.drp.ComITSBusinessTiers10SNAPSHOTStub.LancerCalculDRPResponse;

*/

/**
 * 
 * @author marny
 */
public class CalculDRPServlet extends HttpServlet {
	

	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
	//	LogManager.getLogManager().reset();
		RequestsManager rM = new RequestsManager();
		HttpSession session = request.getSession();
		LoggingOutputStream log =  new LoggingOutputStream();
		log.initializeLog();
		boolean res ;
		
		if (request.getParameter("RlanceDRP")!=null && 
				request.getParameter("RlanceDRP")
				.equals("Relancer le calcul des approvisionnements"))  res = rM.reInitDRP();
		
		//appel web service
		/*ComITSBusinessTiers10SNAPSHOTStub stub = new ComITSBusinessTiers10SNAPSHOTStub();
		LancerCalculDRP lancerCalc = new LancerCalculDRP();
		LancerCalculDRPResponse response1 = stub.lancerCalculDRP(lancerCalc);		
		boolean cDrp = response1.get_return();*/
		
		boolean cDrp = DRPMain.main(null);
		
		//System.out.println("nam "+ cDrp);
		if(cDrp) {
			session.setAttribute("DRPlance",true);
			getServletContext().getRequestDispatcher("/PlanningServlet").forward(request, response);
		}
		else {
			session.setAttribute("DRPlance",true);
			String s ="No";
			request.setAttribute("result", s);			
			getServletContext().getRequestDispatcher("/DRP.jsp?=No").forward(request, response);
		}
	}

}
